<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<t:base type="jquery,easyui,tools"></t:base>
  <t:datagrid name="pushRecordsList" title=""  fitColumns="false" actionUrl="pushRecordsController.do?datagrid" fit="true" idField="id"
              queryMode="group" onLoadSuccess="loadSuccess" sortOrder="desc" sortName="createTime">
    <t:dgCol title="id" field="id" hidden="true"></t:dgCol>

    <t:dgCol title="objectId" field="objectId" hidden="true"></t:dgCol>
    <t:dgCol title="推送标题"   field="title"  sortable="false" query="true"></t:dgCol>
    <t:dgCol title="提示文字"   field="ticker" query="true" sortable="false" ></t:dgCol>
    <t:dgCol title="内容"   field="content"  extendParams="formatter:f_substring;" sortable="false" query="true"></t:dgCol>
    <t:dgCol title="推送类型" field="objectType" dictionary="pushStyle"></t:dgCol>
    <%--<t:dgCol title="新闻公告标题"   field="article.title" sortable="false" query="true"></t:dgCol>--%>
    <t:dgCol title="发送者"   field="sender.realName" sortable="false"></t:dgCol>
    <t:dgCol title="接收方"   field="receiver"  sortable="false"></t:dgCol>
    <t:dgCol title="创建时间"  formatter="yyyy-MM-dd hh:mm:ss" field="createTime" sortable="false"></t:dgCol>

    <t:dgCol title="common.operation" field="opt" ></t:dgCol>
    <t:dgConfOpt message="是否确定重新推送?" operationCode="retryPushRecords" url="pushRecordsController.do?retryPushRecords&id={id}" title="重新推送"></t:dgConfOpt>

    <t:dgToolBar operationCode="pushRecords" title="推送通知" langArg="common.user" icon="icon-add" url="pushRecordsController.do?addorupdate" width="850" funname="add"></t:dgToolBar>
    <%--<t:dgToolBar title="修改" langArg="common.user" icon="icon-edit" url="businessDataController.do?addorupdate" width="850" funname="f_updateBusiness"></t:dgToolBar>--%>
    <%--<t:dgToolBar operationCode="preview" title="预览" langArg="common.user" icon="icon-search" url="articleController.do?preview&id=" funname="f_openPreview"  width="850" height="600"></t:dgToolBar>--%>

  </t:datagrid>

<script type="text/javascript">

  $(function() {

  });

  /**
   * 重写 更新事件打开窗口
   * @param title 编辑框标题
   * @param addurl//目标页面地址
   * @param id//主键字段
   */
  function f_updateBusiness(title,url, id,width,height) {
    gridname=id;
    var rowsData = $('#'+id).datagrid('getSelections');
    if (!rowsData || rowsData.length==0) {
      tip('请选择编辑项目');
      return;
    }
    if (rowsData.length>1) {
      tip('请选择一条记录再编辑');
      return;
    }

    url += '&businessDataId='+rowsData[0].businessDataId;
    createwindow(title,url,width,height);
  }

  function f_openPreview(title,url,gname,width,height){


    var rowsData = $('#'+gname).datagrid('getSelections');
    if (!rowsData || rowsData.length==0) {
      tip('请选择要预览的公告');
      return;
    }
    if (rowsData.length>1) {
      tip('请选择一条记录预览');
      return;
    }

    if(rowsData[0]['objectType'] == "101"){
      tip('非新闻公告不能预览!');
      return;
    }

    if(rowsData[0]['article.id'] == undefined || rowsData[0]['article.id'] == ""){
      tip('该通知没有绑定新闻公告文章!');
      return;
    }

    url += rowsData[0]['article.id'];

    openwindow(title + "[" + rowsData[0].title + "]", url ,gname,width,height);

  }

  function loadSuccess() {

  }


  function f_substring(val,row){
    var newVal = val;
    if(val.length > 20){

      newVal = val.substring(0,20) + "...";
    }

    return "<span title='"+val+"'> " + newVal + " </span>";
  }

</script>
